package com.qixiucoding.config;

import com.qixiucoding.pojo.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySources;

/**
 * @Description TODO
 * @Author longhj
 * @Date 2021/11/27 星期六 13:50
 */
@Configuration
public class MyConditinal {

    // @ConditionalOnMissingBean(User.class)
    // @ConditionalOnClass(User.class)
    @ConditionalOnProperty(prefix = "news",name = "open",havingValue = "false",matchIfMissing = true)
    @Bean(name = "user1")
    public User createUserA() {
        return new User(11, "大龙");
    }

    // @ConditionalOnClass(User.class)
    @ConditionalOnProperty(prefix = "news",name = "open",havingValue = "true")
    @Bean(name = "user1")
    public User createUserB() {
        return new User(22, "大龙2");
    }

}
